/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.basketball.presenter;

import com.suozhang.framework.entity.bo.PageData;
import com.yiqi.lottery.entity.bo.BallMatchBo;
import com.yiqi.lottery.entity.bo.BallMatchBo2;
import com.yiqi.lottery.feature.basketball.contract.BasketballContract;
import com.yiqi.lottery.feature.basketball.dependencies.basketball.DaggerBasketballPresenterComponent;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 *      LIJUWEN
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class BasketballPresenter implements BasketballContract.Presenter {

    private BasketballContract.View mView;

    @Inject

    BasketballContract.Model mModel;


    public BasketballPresenter(BasketballContract.View mView) {
        this.mView = mView;
        DaggerBasketballPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void getBasketballMatchList(String label) {
        if(label.equals("hhgg")){
            mModel.getBasketballMatchList2(label).compose(mView.bindToLife()).subscribe(new Observer<PageData<BallMatchBo2>>() {
                @Override
                public void onSubscribe(Disposable d) {
                    mView.showLoading(d);
                }

                @Override
                public void onNext(PageData<BallMatchBo2> s) {
                    mView.dismissLoading();
                    mView.showBasketballMatchListSuccess2(s);
                }

                @Override
                public void onError(Throwable e) {
                    mView.dismissLoading();
                    mView.showBasketballMatchListError(e.getMessage());
                }

                @Override
                public void onComplete() {
                    mView.dismissLoading();
                }
            });
            return;
        }
       mModel.getBasketballMatchList(label).compose(mView.bindToLife()).subscribe(new Observer<PageData<BallMatchBo>>() {
           @Override
           public void onSubscribe(Disposable d) {
               mView.showLoading(d);
           }

           @Override
           public void onNext(PageData<BallMatchBo> s) {
               mView.dismissLoading();
               mView.showBasketballMatchListSuccess(s);
           }

           @Override
           public void onError(Throwable e) {
               mView.dismissLoading();
               mView.showBasketballMatchListError(e.getMessage());
           }

           @Override
           public void onComplete() {
               mView.dismissLoading();
           }
       });
    }
}
